package android.test;

import android.app.Activity;
import android.os.Bundle;
import android.image.*;
import android.util.Log;
import android.view.Display;
import android.world.VoidWorld;

public class ShowDown extends Activity{
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        Display dis = getWindowManager().getDefaultDisplay();
        new Orient(dis.getWidth(), dis.getHeight()-50).bigBang(this);
    }
}
class Orient extends VoidWorld{
    int WIDTH, HEIGHT;
    double ang;
    double mag;
    
    Orient(int w, int h){
        this.WIDTH = w;
        this.HEIGHT = h;
        this.ang = 0;
        this.mag = 1;
    }
    
    public void onOrientation(double x, double y, double z){
        double ang = Math.acos(x/Math.sqrt(x*x + y*y))+Math.PI;
        if(y < 0){
            this.ang = 2*Math.PI-ang;
        }else{
            this.ang = ang;
        }
        this.mag = Math.sqrt(x*x + y*y);
        Log.d("Testing", "("+x+","+y+" ,"+z+")   MAG = "+mag);
    }

    
    public Scene onDraw(){
        double x = WIDTH/2+Math.cos(ang)*mag*WIDTH/20.0,
               y = HEIGHT/2-Math.sin(ang)*mag*WIDTH/20.0;
        return new EmptyScene(WIDTH, HEIGHT)
             .addLine(WIDTH/2, HEIGHT/2, x, y, "black")
             .placeImage(new Circle(10, "solid", "red"), x, y)
             .placeImage(new Text("Ang: "+((int)(180*ang/Math.PI)), 20, "black"), WIDTH/2, 2*HEIGHT/3)
             .placeImage(new Circle(10, "solid", "blue"), WIDTH/2, HEIGHT/2);
    }
}